From: Marco Trevisan (TreviƱo) Date: Thu, 23 Mar 2023 23:02:16 +0000 (+0100) Subject: shell-app-system: Do not compare startup-wm classes with full desktop IDs X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~371^2^2~18 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=e7a09946ca44a4f4fae6fa847f08e681cfd877cb;p=gnome-shell.git shell-app-system: Do not compare startup-wm classes with full desktop IDs When fetching the desktop ids into a map of startup-wm classes we meant to give the ones that match the desktop ID more priority, however this did not happen because we were always comparing a desktop file id, including the `.desktop` suffix, with a wm-class that generally does not include that. This is the case of gnome-system-monitor, that provides two desktop files, one of which is OnlyShowIn=KDE but both have the same StartupWMClass and thus the first parsed is preferred, even though its desktop-id is gnome-system-monitor-kde. As per this, remove the .desktop suffix when comparing it with the startup-wm-class, keeping the old check just in case. Part-of: --- diff --git a/src/shell-app-system.c b/src/shell-app-system.c index f9d74ed5c..e042a6747 100644 --- a/src/shell-app-system.c +++ b/src/shell-app-system.c @@ -91,6 +91,25 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass) G_TYPE_NONE, 0); } +/* + * Check whether @wm_class matches @id exactly when ignoring the .desktop suffix + */ +static gboolean +startup_wm_class_is_exact_match (const char *id, + const char *wm_class) +{ + size_t wm_class_len; + + if (!g_str_has_prefix (id, wm_class)) + return FALSE; + + wm_class_len = strlen (wm_class); + if (id[wm_class_len] == '\0') + return TRUE; + + return g_str_equal (id + wm_class_len, ".desktop"); +} + static void scan_startup_wm_class_to_id (ShellAppSystem *self) { @@ -116,7 +135,8 @@ scan_startup_wm_class_to_id (ShellAppSystem *self) /* In case multiple .desktop files set the same StartupWMClass, prefer * the one where ID and StartupWMClass match */ old_id = g_hash_table_lookup (priv->startup_wm_class_to_id, startup_wm_class); - if (old_id == NULL || strcmp (id, startup_wm_class) == 0) + if (old_id == NULL || + startup_wm_class_is_exact_match (id, startup_wm_class)) g_hash_table_insert (priv->startup_wm_class_to_id, g_strdup (startup_wm_class), g_strdup (id)); }